#ifndef _SQUIRREL_H
#define _SQUIRREL_H

#include <vector>
#include <squirrel.h>
#include <sqstdio.h>
#include <sqstdmath.h>
#include <sqstdstring.h>
#include <sqstdaux.h>
#include <sqstdblob.h>
#include "Include/SqPlus/sqplus.h"
#include "Main.h"

#ifdef SQUNICODE
#define scvprintf vwprintf
#else
#define scvprintf vprintf
#endif

#ifndef _SQUIRRELDEF
#define _SQUIRRELDEF(x) SQInteger x( HSQUIRRELVM v )
#endif

using namespace SqPlus;

void Print( HSQUIRRELVM v, const SQChar *s, ... );
void Error( HSQUIRRELVM v, const SQChar *s, ... );

class CSquirrel
{
public:
	CSquirrel( unsigned char uc, char* sz );
	~CSquirrel(void);

	unsigned char							GetID					( void )						{ return m_ucID; }
	void									SetID					( unsigned char uc )			{ m_ucID = uc; }

	char*									GetScriptName			( void )						{ return m_szFilename; }
	void									SetScriptName			( char* sz )					{ strcpy( m_szFilename, sz ); }

	HSQUIRRELVM								GetVM					( void )						{ return m_pVM; }

	void									PushFunction			( char* sz );
	void									PushFunction			( void* p );

	void									PushInteger				( int i );
	void									PushFloat				( float f );
	void									PushString				( char* sz );
	void									PushPointer				( void* p );
	void									PushNull				( void );

	void									CallFunction			( void );

private:
	unsigned char							m_ucID;
	char									m_szFilename[ 512 ];

	bool									m_bWaiting;
	unsigned char							m_ucParams;
	int										m_iOrigStack;

	struct SquirrelVMSys					m_pVMSys;
	HSQUIRRELVM								m_pVM;
};

class CSquirrelManager
{
public:
	static CSquirrel*						New						( char* sz );
	static CSquirrel*						New						( unsigned char uc, char* sz );

	static CSquirrel*						Find					( unsigned char uc );
	static CSquirrel*						Find					( char* sz );
	static CSquirrel*						Find					( HSQUIRRELVM v );

	static bool								Remove					( CSquirrel* p );
	static bool								Remove					( unsigned char uc );
	static bool								Remove					( char* sz );

	static void								RemoveAll				( void );

	static unsigned char					Count					( void )						{ return m_ucScripts; }

	static unsigned char					FindFreeID				( void );

private:
	static unsigned char					m_ucScripts;
	static std::vector< CSquirrel* >		m_Scripts;
};

#endif
